import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserModule } from '@/core/user/user.module';
import { AuthModule } from '@/core/auth/auth.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { join } from 'path';
@Module({
  imports: [
    UserModule,
    AuthModule,
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('DATABASE_HOST'),
        port: +configService.get('DATABASE_PORT'),
        username: configService.get('DATABASE_USER'),
        password: configService.get('DATABASE_PASSWORD'),
        database: configService.get('DATABASE_NAME'),
        entities: [
          join(__dirname, 'core/**/*.entity{.ts,.js}'),
          join(__dirname, 'modules/**/*.entity{.ts,.js}'),
        ],
        synchronize: configService.get('NODE_ENV') !== 'production', // 生产环境关闭同步
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}
